<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        姓：<input type="text" v-model="firstName"> +
        名：<input type="text" v-model="lastName"> =
        <span>{{add}}</span><br><br>
        <button @click="fn">改名卡</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                firstName: '刘',
                lastName: '备'
            },
            computed: {
                // 拼接完整姓名
                add: {
                    get() {
                        return this.firstName + this.lastName
                    },
                    set(newVal) {
                        // newVal为新改变的值
                        this.firstName = newVal.substring(0,1)
                        this.lastName = newVal.substring(1)
                    }
                }
            },
            methods: {
                fn(){
                    // 修改姓名
                    this.add='蔡徐坤'
                }
            }
        })
    </script>
</body>

</html>